public class HashBuck2<K,V> {
    static class Node<K,V>{
        public K key;
        public V val;
        public Node<K,V> next;

        public Node(K key, V val) {
            this.key = key;
            this.val = val;
        }
    }
    public Node<K,V>[] arrayNode = (Node<K, V>[]) new Node[10];
    public static final double DEFAULT_LOAD_FACTOR=0.75f;
    public int usedSize;

    public void push(K key,V val){
        int hashCode = key.hashCode();
        int index = hashCode % arrayNode.length;
        Node<K,V> cur = arrayNode[index];
        while(cur!=null){
            if (cur.key.equals(key)){
                cur.val=val;
                return ;
            }
            cur=cur.next;
        }
        Node<K,V> curN = new Node<>(key,val);
        curN.next = arrayNode[index];
        arrayNode[index]=curN;
        usedSize++;

        if(doLOADFACTOR()>=DEFAULT_LOAD_FACTOR){
            resize();
        }
    }
    private double doLOADFACTOR(){
        return usedSize*1.0/ arrayNode.length;
    }

    private void resize(){
        Node<K,V>[] newarrayNode = (Node<K, V>[]) new Node[2* arrayNode.length];
        for (int i=0;i< arrayNode.length;i++){
            Node cur = arrayNode[i];
            while(cur!=null){
                Node<K,V> curN=null;
                int hashCode = cur.key.hashCode();
                int newIndex= hashCode% newarrayNode.length;
                curN=cur.next;

                cur.next=newarrayNode[newIndex];
                newarrayNode[newIndex] = cur;
                cur=curN;
            }
        }
        arrayNode=newarrayNode;
    }

    public V getVal(K key){
        int hashCode = key.hashCode();
        int index = hashCode % arrayNode.length;
        Node<K,V> cur = arrayNode[index];

        while(cur!=null){
            if (cur.key.equals(key)){
                return cur.val;
            }
            cur=cur.next;
        }
        return null;
    }
}
